package com.changgou.config.controller;

import com.changgou.config.pojo.Provinces;
import com.changgou.config.service.ProvincesService;
import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/provinces")
public class ProvincesController {


    @Autowired
    private ProvincesService provincesService;

    /**
     * 查询所有省份
     * @return
     */
    @GetMapping
    public Result findAll(){
        try {
            List<Provinces> provincesList = provincesService.findAll();
            return new Result(true, StatusCode.OK,"查询成功",provincesList) ;
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }


}
